package com.petshop.customers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.petshop.common.annotation.Log;
import com.petshop.common.core.controller.BaseController;
import com.petshop.common.core.domain.AjaxResult;
import com.petshop.common.enums.BusinessType;
import com.petshop.customers.domain.PetCustomers;
import com.petshop.customers.service.IPetCustomersService;
import com.petshop.common.utils.poi.ExcelUtil;
import com.petshop.common.core.page.TableDataInfo;

/**
 * 顾客信息Controller
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/customers/customers")
public class PetCustomersController extends BaseController
{
    @Autowired
    private IPetCustomersService petCustomersService;

    /**
     * 查询顾客信息列表
     */
    @PreAuthorize("@ss.hasPermi('customers:customers:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetCustomers petCustomers)
    {
        startPage();
        List<PetCustomers> list = petCustomersService.selectPetCustomersList(petCustomers);
        return getDataTable(list);
    }

    /**
     * 导出顾客信息列表
     */
    @PreAuthorize("@ss.hasPermi('customers:customers:export')")
    @Log(title = "顾客信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetCustomers petCustomers)
    {
        List<PetCustomers> list = petCustomersService.selectPetCustomersList(petCustomers);
        ExcelUtil<PetCustomers> util = new ExcelUtil<PetCustomers>(PetCustomers.class);
        util.exportExcel(response, list, "顾客信息数据");
    }

    /**
     * 获取顾客信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('customers:customers:query')")
    @GetMapping(value = "/{customerID}")
    public AjaxResult getInfo(@PathVariable("customerID") Long customerID)
    {
        return success(petCustomersService.selectPetCustomersByCustomerID(customerID));
    }

    /**
     * 新增顾客信息
     */
    @PreAuthorize("@ss.hasPermi('customers:customers:add')")
    @Log(title = "顾客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetCustomers petCustomers)
    {
        return toAjax(petCustomersService.insertPetCustomers(petCustomers));
    }

    /**
     * 修改顾客信息
     */
    @PreAuthorize("@ss.hasPermi('customers:customers:edit')")
    @Log(title = "顾客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetCustomers petCustomers)
    {
        return toAjax(petCustomersService.updatePetCustomers(petCustomers));
    }

    /**
     * 删除顾客信息
     */
    @PreAuthorize("@ss.hasPermi('customers:customers:remove')")
    @Log(title = "顾客信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIDs}")
    public AjaxResult remove(@PathVariable Long[] customerIDs)
    {
        return toAjax(petCustomersService.deletePetCustomersByCustomerIDs(customerIDs));
    }
}
